import json
import pandas as pd
from ths.codeList import Tonghuashun
import baostock as bs
import talib
from util.GetBaostockDatByDataFrame import GetBaostockDataFrame

if __name__ == "__main__":
    try:

        lg = bs.login(user_id='anonymous', password='123456')
        t = Tonghuashun("test",
                        "user_status=0; Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1663426762,1663469443; Hm_lvt_da7579fd91e2c6fa5aeb9d1620a9b333=1663426762,1663471001; log=; user=MDq35kh0Njo6Tm9uZTo1MDA6MzI4ODA3NTY4OjcsMTExMTExMTExMTEsNDA7NDQsMTEsNDA7NiwxLDQwOzUsMSw0MDsxLDEwMSw0MDsyLDEsNDA7MywxLDQwOzUsMSw0MDs4LDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAxLDQwOzEwMiwxLDQwOjI0Ojo6MzE4ODA3NTY4OjE2NjM1MDIxODY6OjoxNDUyODE0ODYwOjYwNDgwMDowOjEyZjg5MzM2YWMzYjI1MjU0ODRjNzUxNTczNzIzZGVkYzpkZWZhdWx0XzQ6MQ%3D%3D; userid=318807568; u_name=%B7%E6Ht6; escapename=%25u950bHt6; ticket=e6dc54e71c34920c1bae44eccf3ed161; utk=89e9cf778e3294cc8780fa4f54f3dbb9; Hm_lpvt_da7579fd91e2c6fa5aeb9d1620a9b333=1663502187; Hm_lpvt_78c58f01938e4d85eaf619eae71b4ed1=1663502187; v=A2VOv6XnakPVt46f0I768WindCqaohkrY1X9iGdKJQmqrItUL_IpBPOmDVH0")
        data = t.get_stocks()
        t.modify_stock('603019', 'add', None)
        t.modify_stock('000938', 'add', None)
        for index, row in data.iterrows():
            code = row['code']
            print(code)
            #t.modify_stock('603019', 'add', pos=index)

        print("运行完成!")



















        #t = Tonghuashun("test", "user_status=0; log=; Hm_lvt_f79b64788a4e377c608617fba4c736e2=1663469443; Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1663426762,1663469443; cmsad_156_1=0; cmsad_152_1=0; cmsad_150_0=0; cmsad_160_1=0; user=MDq35kh0Njo6Tm9uZTo1MDA6MzI4ODA3NTY4OjcsMTExMTExMTExMTEsNDA7NDQsMTEsNDA7NiwxLDQwOzUsMSw0MDsxLDEwMSw0MDsyLDEsNDA7MywxLDQwOzUsMSw0MDs4LDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAxLDQwOzEwMiwxLDQwOjI0Ojo6MzE4ODA3NTY4OjE2NjM0Njk0Njc6OjoxNDUyODE0ODYwOjYwNDgwMDowOjE0NDc4OTcyZjg2NGE3ZWFiNDE2NzZkODJlNjYwZTIwNzpkZWZhdWx0XzQ6MQ%3D%3D; userid=318807568; u_name=%B7%E6Ht6; escapename=%25u950bHt6; ticket=2c44535375476af83bda4c7f04018e5c; utk=54cdad4f3d3fe57b3e86e436ba6a3c78; Hm_lpvt_78c58f01938e4d85eaf619eae71b4ed1=1663469470; cmsad_152_0=0; Hm_lpvt_f79b64788a4e377c608617fba4c736e2=1663469470; v=A5a90mIS6UfZI93jt9DZ1De650edN9pULHoO1QD_h3kUyDj5aMcqgfwLXurT")
        #data = t.get_stocks()
        #for index, row in data.iterrows():
        #    code = row['code']
            #t.modify_stock(code, 'del', pos='1')

        #添加
        #boo = t.modify_stock('834475', 'add', pos='1')
        #if boo :
        #    print('修改成功')


        #print(data)

    except Exception as err:
        print("Finished with error: ", err)